package TAIC.text;

import java.io.File;
import java.util.HashMap;
import java.util.Scanner;

public class Dict {
	public static void main ( String argu []  ) { 
		
	}
	
	public Dict ( String filename ) {
		this.filename = filename; 
	}
	
	public Translation getTranslation ( int id ) {
		if ( dict == null ) init ();
		return dict.get( id ) ;
	}
	
	void init () {
		if ( dict != null ) return ; 
		dict = new HashMap < Integer, Translation > () ;
		try {
			File file = new File ( filename ) ;
			if ( file.exists() ){
				Scanner scanner = new Scanner ( file );
				while ( scanner.hasNextInt() ){
					Translation tr = new Translation (); 
					int id = scanner.nextInt() ;
					int num = scanner.nextInt() ;
					for ( int i = 0; i < num ;i ++ ) 
						tr.add( new WordProb( scanner.nextInt() , scanner.nextDouble() ) )  ;
					dict.put( id , tr) ; 
				}
				scanner.close() ;
			}
		}catch ( Exception e ) {
			
		}
	}
	
	static HashMap < Integer, Translation  > dict = null ;
	String filename; 
}
